<?
/* AgataQuery
 *
 */
class AgataQuery
{
    var $conn;     // the connection id
    var $sql;      // the SQL command string
    var $result;   // the SQL command result set
    var $row;      // the current row index
    var $db;
    var $TableInfo;

    /***********************************************************/
    /* Constructor method
    /***********************************************************/
    function AgataQuery($agataConfig)
    {
        $this->agataConfig = $agataConfig;
    }

    /***********************************************************/
    /* Open a query
    /***********************************************************/
    function Open($db)
    {
        $this->result=$db->query($this->sql);
        $this->TableInfo = null;
        
        if (DB::isError($this->result) || (!$this->result))
        {
            new Dialog(Cut($this->result->userinfo, 'ERROR:'));
            $this->result =0;
            return false;
        }
        
        return true;
    }

    /***********************************************************/
    /* Get the number of rows
    /***********************************************************/
    function GetRowCount()
    {
        return $this->result->numRows();
    }

    /***********************************************************/
    /* Get the number of columns
    /***********************************************************/
    function GetColumnCount()
    {
        if (!$this->result)
        {
            echo "error \n";
        }
        
        return $this->result->numCols();
    }

    /***********************************************************/
    /* Get the names of columns
    /***********************************************************/
    function GetColumnNames()
    {
        if ($this->Gateway == "odbc")
        {
            $Result = $this->result->result;
            for ($n=1; $n<=odbc_num_fields($Result); $n++)
            {
                $strings[] = odbc_field_name($Result, $n);
            }
        }
        else
        {
            if (!$this->TableInfo)
            {
                $this->TableInfo = $this->result->TableInfo();
            }
            
            $Results = $this->TableInfo;
            foreach ($Results as $Result)
            {
                $strings[] = $Result['name'];
            }
        }
        return $strings;
    }

    /***********************************************************/
    /* Get the types of columns
    /***********************************************************/
    function GetColumnTypes()
    {
        if ($this->Gateway == "odbc")
        {
            $Result = $this->result->result;
            for ($n=1; $n<=odbc_num_fields($Result); $n++)
            {
                $strings[] = odbc_field_type($Result, $n);
            }
        }
        else
        {
            if (!$this->TableInfo)
            {
                $this->TableInfo = $this->result->TableInfo();
            }
            $Results = $this->TableInfo;
            foreach ($Results as $Result)
            {
                $strings[] = $Result['type'];
            }
        }
        return $strings;
    }
}
?>